package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: Tangguo
 * @Date: 2023-06-05  15:57
 */
@RestController
@RequestMapping("/api/v1/article/")
@Slf4j
public class ArticleHomeController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * app文章列表-加载首页
     * @param dto:
     * @return ResponseResult
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        log.info("加载首页,入参：{}",dto);
        return apArticleService.loadFirstPage(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * app文章列表-加载最新
     * @param dto:
     * @return ResponseResult
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNews(@RequestBody ArticleHomeDto dto) {
        log.info("加载最新,入参：{}",dto);
        return apArticleService.load(dto,ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * app文章列表-加载更多
     * @param dto:
     * @return ResponseResult
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        log.info("加载更多,入参：{}",dto);
        return apArticleService.load(dto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }
}
